<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
	function displayObject() {
		var file = ($("#path").val());
		var fileName = "";
		if (file) {
		    var startIndex = (file.indexOf('\\') >= 0 ? file.lastIndexOf('\\') : file.lastIndexOf('/'));
		    fileName = file.substring(startIndex);
		    if (fileName.indexOf('\\') === 0 || fileName.indexOf('/') === 0) {
		        fileName = fileName.substring(1);
		    }
		}

        if (fileName == "") {  
            $.messager.alert('Lỗi !','Bạn chưa chọn file Excel');          
        }  
        else {
        	 if(!fileName.match(/\.(xls)|(xlsx)$/)){  
        		 $.messager.alert('Lỗi !','File Bạn chọn không phải file Excel');
        	 }else{
				$('#tt').datagrid('load', {
					name : fileName,
				});
        	 }
        }
	}
	
function importObject() {
	var file = ($("#path").val());
    if (file == "") {  
        $.messager.alert('Lỗi !','Bạn chưa chọn file Excel');          
    }  
    else {
		$.post("ExcelServlet?flag=import", {
		}, function(result) {
			if (result.success) {
				$.messager.alert("Import",result.msg);
			} else {
				$.messager.alert("Import",result.msg);
			}
		}, "json");
    }
}

function testObject() {
	var file = ($("#path").val());
    if (file == "") {  
        $.messager.alert('Lỗi !','Bạn chưa chọn file Excel');          
    }  
    else {
		$.post("ExcelServlet?flag=test", {
		}, function(result) {
			if (result.success) {
				$.messager.alert("Kiểm tra",result.msg);
			} else {
				$.messager.alert("Kiểm tra",result.msg);
			}
		}, "json");
    }
}
</script>
<style type="text/css">
#fm {
	margin: 0;
	padding: 5 0px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	color: #000000;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 7px;
}

.fitem label {
	display: inline-block;
	width: 90px;
}

.fitem input {
	display: inline-block;
	width: 250px;
	background: none repeat scroll 0 0 #FFFFFF;
	border: 1px solid #888888;
	border-radius: 5px 5px 5px 5px;
	color: #222222;
	margin: 0 5px 0 0;
	padding: 3px 3px;
}
</style>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
	<table id="tt" class="easyui-datagrid"
		style="width: 795px; height: 574px" url="ExcelServlet"
		title=":: MÔN HỌC" toolbar="#tb" rownumbers="true" pagination="true"
		singleSelect="true" fitColumns="true">
		<thead>
			<tr>
				<th field="ma">Mã</th>
				<th field="ten">Tên Môn Học</th>
				<th field="so_tc">Số TC</th>
				<th field="so_tiet_lt">Số Tiết LT</th>
				<th field="so_tiet_th">Số Tiết TH</th>
				<th field="ma_don_vi">Mã Đơn Vị</th>
			</tr>
		</thead>
	</table>

	<div id="tb" style="padding: 5px">
		<div style="padding: 5px">
			<input id="path" name="path" type="file"> 
			<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-display" onclick="displayObject()">Hiển Thị</a>
			<a id="test" href="#" class="easyui-linkbutton" plain="true" iconCls="icon-test" onclick="testObject()">Kiểm tra</a>
			<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-import" onclick="importObject()">Import</a>
		</div>
	</div>
</form>
</body>
</html>